# Statistical test for results
# 
exp.ttest <- function(exppar, alt="two.sided"){
# arguments:
#  exppar: object name of experiment results, a list

    nexp <- 4
    out0401 <- apply(exppar$co.as,1,mean)
    out0402 <- apply(exppar$co.ws,1,mean)
    out0403 <- apply(exppar$co.mo,1,mean)
    out0405 <- apply(exppar$co.ai,1,mean)
    out0406 <- apply(exppar$co.wi,1,mean)
    
    ttest.pv <- matrix(ncol=4,nrow=4,dimnames=list(c("AS","WS","AI","WI"),c("WS","AI","WI","MO")))
    ttest.tv <- matrix(ncol=4,nrow=4,dimnames=list(c("AS","WS","AI","WI"),c("WS","AI","WI","MO")))

    ttest.pv[1,1] <- t.test(out0401, y=out0402, alternative=alt, paired=T)$p.value
    ttest.pv[1,2] <- t.test(out0401, y=out0405, alternative=alt, paired=T)$p.value
    ttest.pv[1,3] <- t.test(out0401, y=out0406, alternative=alt, paired=T)$p.value
    ttest.pv[1,4] <- t.test(out0401, y=out0403, alternative=alt, paired=T)$p.value
    ttest.pv[2,2] <- t.test(out0402, y=out0405, alternative=alt, paired=T)$p.value
    ttest.pv[2,3] <- t.test(out0402, y=out0406, alternative=alt, paired=T)$p.value
    ttest.pv[2,4] <- t.test(out0402, y=out0403, alternative=alt, paired=T)$p.value
    ttest.pv[3,3] <- t.test(out0405, y=out0406, alternative=alt, paired=T)$p.value
    ttest.pv[3,4] <- t.test(out0405, y=out0403, alternative=alt, paired=T)$p.value
    ttest.pv[4,4] <- t.test(out0406, y=out0403, alternative=alt, paired=T)$p.value

    ttest.tv[1,1] <- t.test(out0401, y=out0402, alternative=alt, paired=T)$statistic
    ttest.tv[1,2] <- t.test(out0401, y=out0405, alternative=alt, paired=T)$statistic
    ttest.tv[1,3] <- t.test(out0401, y=out0406, alternative=alt, paired=T)$statistic
    ttest.tv[1,4] <- t.test(out0401, y=out0403, alternative=alt, paired=T)$statistic
    ttest.tv[2,2] <- t.test(out0402, y=out0405, alternative=alt, paired=T)$statistic
    ttest.tv[2,3] <- t.test(out0402, y=out0406, alternative=alt, paired=T)$statistic
    ttest.tv[2,4] <- t.test(out0402, y=out0403, alternative=alt, paired=T)$statistic
    ttest.tv[3,3] <- t.test(out0405, y=out0406, alternative=alt, paired=T)$statistic
    ttest.tv[3,4] <- t.test(out0405, y=out0403, alternative=alt, paired=T)$statistic
    ttest.tv[4,4] <- t.test(out0406, y=out0403, alternative=alt, paired=T)$statistic
    
    
    print(list(p.value=ttest.pv,t.score=ttest.tv))
    invisible(list(p.value=ttest.pv,t.score=ttest.tv))
}

exp.ttest2 <- function(exppar, alt="two.sided"){
# arguments:
#  exppar: object name of experiment results, a list

    nexp <- 4
    out0515 <- apply(exppar$as.ai,1,mean)
    out0516 <- apply(exppar$as.wi,1,mean)
    out0525 <- apply(exppar$ws.ai,1,mean)
    out0526 <- apply(exppar$ws.wi,1,mean)
    
    ttest.pv <- matrix(ncol=3,nrow=3,dimnames=list(c("ASAI","ASWI","WSAI"),c("ASWI","WSAI","WSWI")))
    ttest.tv <- matrix(ncol=3,nrow=3,dimnames=list(c("ASAI","ASWI","WSAI"),c("ASWI","WSAI","WSWI")))

    ttest.pv[1,1] <- t.test(out0515, y=out0516, alternative=alt, paired=T)$p.value
    ttest.pv[1,2] <- t.test(out0515, y=out0525, alternative=alt, paired=T)$p.value
    ttest.pv[1,3] <- t.test(out0515, y=out0526, alternative=alt, paired=T)$p.value
    ttest.pv[2,2] <- t.test(out0516, y=out0525, alternative=alt, paired=T)$p.value
    ttest.pv[2,3] <- t.test(out0516, y=out0526, alternative=alt, paired=T)$p.value
    ttest.pv[3,3] <- t.test(out0525, y=out0526, alternative=alt, paired=T)$p.value

    ttest.tv[1,1] <- t.test(out0515, y=out0516,, alternative=alt, paired=T)$statistic
    ttest.tv[1,2] <- t.test(out0515, y=out0525, alternative=alt, paired=T)$statistic
    ttest.tv[1,3] <- t.test(out0515, y=out0526, alternative=alt, paired=T)$statistic
    ttest.tv[2,2] <- t.test(out0516, y=out0525, alternative=alt, paired=T)$statistic
    ttest.tv[2,3] <- t.test(out0516, y=out0526, alternative=alt, paired=T)$statistic
    ttest.tv[3,3] <- t.test(out0525, y=out0526, alternative=alt, paired=T)$statistic
    
    
    print(list(p.value=ttest.pv,t.score=ttest.tv))
    invisible(list(p.value=ttest.pv,t.score=ttest.tv))
}
